package leetcode.problems;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by gmwang on 2018/7/25
 * 键盘行
 */
public class _0811SubdomainVisitCount {
    /**
     * Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.
     * 给定单词列表，返回仅一行美国键盘上可以使用字母输入的单词，如下图所示
     * Example:
     *
     * Input: ["Hello", "Alaska", "Dad", "Peace"]
     * Output: ["Alaska", "Dad"]
    /**
     *
     * @param words
     * @return
     */
    public String[] findWords(String[] words) {
        List<String> list = new ArrayList<>();
        String r1 = "qwertyuioQEERTYUIO";
        String r2 = "asdfghjklASDFGHJKL";
        String r3 = "zxcvbnmZXCVBNM";
        int k = 0;
        int mark = 0;
        outer:for (int i = 0; i < words.length; i++) {
            char[] word = words[i].toCharArray();
            mark=0;
            for (int j = 0; j < word.length; j++) {
                //属于第一行
                if(r1.contains(word[j]+"")){
                    if(mark !=0 && mark != 1) continue outer;
                    mark = 1;
                }
                if(r2.contains(word[j]+"")) {
                    if(mark !=0 && mark != 2) continue outer;
                    mark = 2;
                }
                if(r3.contains(word[j]+"")){
                    if(mark !=0 && mark != 3) continue outer;
                    mark = 3;
                }
            }
            list.add(words[i]);
        }
        String [] result = new String[list.size()];
        return list.toArray(result);
    }
    @Test
    public void test() {
//        String ints = "hello";
//        String[] words = {"Hello", "Alaska", "Dad", "Peace"};
        String[] words = {"b", "a"};
//        String[] ints = {"900 google.mail.com", "50 yahoo.com", "1 intel.mail.com", "5 wiki.org"};
        String[] res = findWords(words);
        System.out.println(Arrays.toString(res));
    }
}
